package com.spyx.sys.controller;


import com.atyx.spyx.model.sys.RegionWare;
import com.atyx.spyx.vo.sys.RegionWareQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spyx.result.Result;
import com.spyx.sys.service.RegionWareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 城市仓库关联表 前端控制器
 * </p>
 *
 * @author yhp
 * @since 2024-05-14
 */
@RestController
@RequestMapping("/admin/sys/regionWare")
@Api(tags = "区域管理")
//@CrossOrigin
public class RegionWareController {
    @Autowired
    private RegionWareService regionWareService;

    //分页+模糊查
    @GetMapping("/{page}/{limit}")
    @ApiOperation("获取区域列表")
    public Result getList(@PathVariable("page")Integer page,
                          @PathVariable("limit")Integer limit,
                          RegionWareQueryVo    queryVo){
        Page p1 = new Page(page, limit);
        IPage<RegionWare> pageModel= regionWareService.getReginWareList(p1,queryVo);
        return Result.ok(pageModel);
    }

    //保存
    @ApiOperation("保存区域")
    @PostMapping("/save")
    public Result save(@RequestBody RegionWare regionWare){
        //保存被开通区域时，需要先验证该区域是否已开通过
        regionWareService.saveRegionWare(regionWare);
        return Result.ok();
    }

    //删除某个区域
    @ApiOperation("删除区域")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable("id") Integer id){
        regionWareService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("取消开通")
    @PostMapping("/updateStatus/{id}/{status}")
    public Result update(@PathVariable("id")Integer id,  // 区域id
                         @PathVariable("status")Integer status){  //区域状态
        //这里不能直接调取updateById(RegionWare regionWare),这个方法的参数是RegionWare regionWare
        regionWareService.updateRegionware(id,status);
        return Result.ok();
    }

}

